﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UCLibrary.UC
{
    public partial class UCPot : UserControl
    {
        public UCPot()
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }
        private Color _potlColor = Color.Gray;
        [Description("容器颜色")]
        public Color potlColor
        {
            get { return _potlColor; }
            set { _potlColor = value; Refresh(); }
        }

        private Color _levelColor = Color.SkyBlue; 
        [Description("液体颜色")]
        public Color levelColor
        {
            get { return _levelColor; }
            set { _levelColor = value;Refresh(); }
        }
        private float level;
        [Description("液位实际百分比")]
        public float Level
        {
            get { return level; }
            set 
            { 
                if(value>100f)
                    level = 100f;
                else
                    level = value;
                Refresh();
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Function.setHighQuality( g);
            float width = Width - 10;
            float height = Height - 5;
            float actualLevel = level * height / 100;
            g.FillRectangle(new SolidBrush(levelColor),5,height-actualLevel , width, actualLevel);
            g.DrawLines(new Pen(potlColor, 10), new Point[]
            {
                new Point(0,0),
                new Point(0,Height),
                new Point(Width,Height),
                new Point(Width,0)
            });

        }
    }
}
